

CXX	:= g++
LD	:= g++
AR	:= ar
CXXFLAGS := -Wall -O2 -Werror
INCLUDES = -I../ -I../serialize -I../archive_binary

TARGET	= libUft.a
UNITEST = a.out
LINKS	= -L.
LIBS	= -lpthread

# SOURCES := main.cc
SOURCES += Uft.cc
SOURCES += logging.cc
SOURCES += UftClient.cc
SOURCES += UftServer.cc
SOURCES += UfServerNode.cc
SOURCES += UfPacket.cc
SOURCES += UfBuffer.cc
SOURCES += UfTimeout.cc
SOURCES += UfFile.cc
SOURCES += UfPartitions.cc
SOURCES += UfConvert.cc
SOURCES += UfPieceBuffer.cc
SOURCES += UfWorkThread.cc
SOURCES += UfThreadPool.cc
SOURCES += UfMessenger.cc
SOURCES += md5.cc

SOURCES += ../tools/socket.cc
SOURCES += ../tools/thread.cc
SOURCES += ../tools/lock.cc
SOURCES += ../tools/dump.cc
SOURCES += ../archive_binary/archive.cc

OBJS := $(SOURCES:.cc=.o)
DEPS := $(SOURCES:.cc=.d)

all: prebuild $(TARGET) $(UNITEST)

$(TARGET): $(OBJS)
	@echo Linking $@ ...
	@# $(LD) $(OBJS) $(LINKS) $(LIBS) -o$@
	$(AR) crs $(TARGET) $(OBJS)
	@echo -------------------------------------------
	@echo done.

$(UNITEST): main.o $(TARGET)
	@echo Linking $@ ...
	$(LD) main.o $(TARGET) $(LINKS) $(LIBS) -o$@
	@echo -------------------------------------------
	@echo done.

.cc.o:
	@echo Compling $@ ...
	$(CXX) -c $< $(INCLUDES) $(CXXFLAGS)  -o $@
	@echo -------------------------------------------


%.d:%.cc
	$(CXX) -MM $< $(INCLUDES) $(CXXFLAGS) -o $@

prebuild:
	#echo -------

include $(DEPS)

clean:
	rm -fr $(OBJS) $(DEPS) $(TARGET) $(UNITEST) main.o aaa.tmp



